<?php
//Have to be declared before I do any xhtml outputs. (aka have to be send with the headers)
session_start();

//Write good explanation... TODO TODO TODO
ini_set('display_errors', 1); 
//ini_set('log_errors', 1); 
//ini_set('error_log', dirname(__FILE__) . '/error_log.txt'); 
error_reporting(E_ALL);

//require_one includes documents so that they're accessible throughout all documents in the project.
require_once("view/MemberView.php");
require_once("view/FileUploadView.php");
require_once ("view/LoginView.php");
require_once ("view/PageView.php");

require_once("model/FileUploadHandler.php");
require_once("model/MemberHandler.php");
require_once ("model/LoginHandler.php");
require_once ("model/Member.php");
require_once ("model/MemberDAL.php");

require_once("controller/FileUploadController.php");
require_once ("controller/LoginController.php");
require_once("controller/MasterController.php");
require_once("controller/MemberController.php");
require_once("controller/LoggedInController.php");

require_once ("common/config.php");
require_once ("common/settings.php");
require_once ("common/Validate.php");
require_once ("common/DBConnection.php");
require_once ("view/NavigationView.php");
require_once ("view/PageCompositionView.php");

require_once("tests/TestAll.php");

//Creates instances of loginhandler, loginview, logincontroller and so on.

//Create new connection to the database
$dbconnection  = new DBConnection();

$userTableName = "project";

$memberDAL = new memberDAL($dbconnection, $userTableName);
$loginHandler = new LoginHandler($memberDAL);
$validate = new Validate();
$memberView = new MemberView($dbconnection, $userTableName, $validate);
$memberHandler = new MemberHandler($dbconnection, $userTableName, $memberDAL);
$loginController = new LoginController ($dbconnection, $userTableName, $memberDAL, $loginHandler, $memberHandler, $memberView);
$testAll = new TestAll($memberDAL, $loginHandler, $memberView, $memberHandler, $loginController);

//Connect to database
$dbconnection->Connect();

$masterController = new MasterController($dbconnection, $userTableName, $memberDAL, $loginHandler, $memberHandler, $memberView, $validate);

$pageView = new PageView ();

//Test tests
$testResult = $testAll -> TestAll();

$xhtml ="";

if($memberHandler->TestMemberHandler() == true) {
    $xhtml.= "valideringstestet slutfördes utan fel!" ;

} else {
    $xhtml .= "<br />valideringstestet fungerade inte alls!" ;
}

//set page title
$title = "Min titel";

//xhtml that will show in body
$xhtml = $testResult;


//Link stylesheet
$pageView -> AddStyleSheet("css/reset.css");
$pageView -> AddStyleSheet("css/regular.css");

//Writes Xhtml for body and head.
echo $pageView -> GetXHTML10StrictPage($title, $xhtml);
//Don't have ? > if you accidentally have a space or tab after the end sign it will print on clientside. 
